import request from "@/utils/request";

export const loadApprovalGroupListReq = (companyId, moduleType = "hr") => {
  return request({
    url: `/approval/api/v1/approFlowGroups/allGroupAndFlowByCompanySite/${companyId}/${moduleType}`,
    method: "get"
  });
};

export const loadApprovalTypeListReq = (moduleType = "hr") => {
  return request({
    url: `/approval/api/v1/approTypes/listAll`,
    method: "get",
    params: {
      moduleType: moduleType
    }
  });
};

export const loadFormByTypeReq = flowType => {
  return request({
    url: `/approval/api/v1/approFlowForms/allByType/${flowType}`,
    method: "get"
  });
};

export const getFlowDetailReq = flowId => {
  return request({
    url: `/approval/api/v1/approFlows/allFolwProcess/${flowId}`,
    method: "get"
  });
};

export const getApprovalDetail = flowId => {
  return request({
    url: `/approval/api/v1/approFlows/allFolwInfo/${flowId}?moduleType=hr`,
    method: "get"
  });
};

export const publishApproval = data => {
  return request({
    url: "/hr/api/v1/approval/publishFlow", // `/approval/api/v1/approFlows/publishFlow`,
    method: "post",
    data: data
  });
};

export function approvalDetailReq(approvalId) {
  return request({
    url: `/hr/api/v1/hrApproProviders/userApproDetails/${approvalId}`,
    method: "get"
  });
}

export function approvalHandlerAgreeReq(approvalId, data) {
  return request({
    url: `/approval/api/v1/userFlowApprovers/pass/${approvalId}`,
    method: "put",
    data
  });
}

export function approvalHandlerRejectReq(approvalId, data) {
  return request({
    url: `/approval/api/v1/userFlowApprovers/reject/${approvalId}`,
    method: "put",
    data
  });
}

export function selectByUserApproval(data) {
  return request({
    url: `/hr/api/v1/costBills/selectByUserApprovalId`,
    method: "get",
    params: {
      userApprovalId: data
    }
  });
}
